﻿Option Strict On

Imports System.IO
Imports System.Text

Namespace FTP
    ''' <summary>
    ''' The FtpItem class represents the file and directory listing items as reported by the FTP server.
    ''' </summary>
    ''' <remarks>
    ''' Usually items are of types Files and Directories although
    ''' the Unix based FTP servers may report additional information such as permissions and symbolic link information.  The FtpItem class supports
    ''' the most commom versions of Unix, Windows, DOS, and Machintosh Ftp Servers.  There is no FTP standard concerning how an FTP server should
    ''' list file item data.  Therefore, the FtpClient object supports a pluggable ftp item parser that you can write to support more exotic
    ''' ftp item listing formats.
    ''' </remarks>
    Public Class FtpItem
        Private _name As String
        Private _modified As DateTime
        Private _size As Long
        Private _symbolicLink As String
        Private _itemType As FtpItemType
        Private _attributes As String
        Private _rawText As String
        Private _parentPath As String

        ''' <summary>
        ''' Constructor to create a new ftp item.
        ''' </summary>
        ''' <param name="name">Name of the item.</param>
        ''' <param name="modified">Modified date and/or time of the item.</param>
        ''' <param name="size">Number of bytes or size of the item.</param>
        ''' <param name="symbolicLink">Symbolic link name.</param>
        ''' <param name="attributes">Permission text for item.</param>
        ''' <param name="itemType">Type of the item.</param>
        ''' <param name="rawText">The raw text of the item.</param>
        Public Sub New(ByVal name As String, ByVal modified As DateTime, ByVal size As Long, ByVal symbolicLink As String, ByVal attributes As String, ByVal itemType As FtpItemType, _
         ByVal rawText As String)
            _name = name
            _modified = modified
            _size = size
            _symbolicLink = symbolicLink
            _attributes = attributes
            _itemType = itemType
            _rawText = rawText
        End Sub

        ''' <summary>
        ''' Item name.  All FTP servers should report a name value for the FTP item.
        ''' </summary>
        Public ReadOnly Property Name() As String
            Get
                Return _name
            End Get
        End Property

        ''' <summary>
        ''' Permissions text for the item.  Many FTP servers will report file permission information.
        ''' </summary>
        Public ReadOnly Property Attributes() As String
            Get
                Return _attributes
            End Get
        End Property

        ''' <summary>
        ''' Modified date and possibly time for the ftp item.
        ''' </summary>
        Public ReadOnly Property Modified() As DateTime
            Get
                Return _modified
            End Get
        End Property

        ''' <summary>
        ''' The size of the ftp item as reported by the FTP server.
        ''' </summary>
        Public ReadOnly Property Size() As Long
            Get
                Return _size
            End Get
        End Property

        ''' <summary>
        ''' The symbolic link name if the item is of itemType symbolic link.
        ''' </summary>
        Public ReadOnly Property SymbolicLink() As String
            Get
                Return _symbolicLink
            End Get
        End Property

        ''' <summary>
        ''' The itemType of the ftp item.
        ''' </summary>
        Public ReadOnly Property ItemType() As FtpItemType
            Get
                Return _itemType
            End Get
        End Property

        ''' <summary>
        ''' The raw textual line information as reported by the FTP server.  This can be useful for examining exotic FTP formats and for debugging
        ''' a custom ftp item parser.
        ''' </summary>
        Public ReadOnly Property RawText() As String
            Get
                Return _rawText
            End Get
        End Property

        ''' <summary>
        ''' Path to the parent directory.
        ''' </summary>
        Public Property ParentPath() As String
            Get
                Return _parentPath
            End Get
            Set(ByVal value As String)
                _parentPath = value
            End Set
        End Property

        ''' <summary>
        ''' Item full path.
        ''' </summary>
        Public ReadOnly Property FullPath() As String
            Get
                Return If(_parentPath = "/" OrElse _parentPath = "//", String.Format("{0}{1}", _parentPath, _name), String.Format("{0}/{1}", _parentPath, _name))
            End Get
        End Property

    End Class
End Namespace